#ifndef BSON_H
#define BSON_H

typedef enum BSONType {
    BSONOBJ = 1,

    STRING = 16,
    INTEGER,
    BOOL,
    FLOAT,
    DATE,
    ARRAY
} BSONType;

typedef struct Obj {
    enum BSONType type;
    short length;
} Obj;

typedef struct BSONObj {
    enum BSONType type;
    short length;
    short propertyId;
    char *data;
} BSONObj;

#define OBJ_LENGTH sizeof(Obj)
#define BSONOBJ_FIXED_LENGTH (OBJ_LENGTH + sizeof(short))
#define BSONObjLength(x) ((x)->length + OBJ_LENGTH)
#define BSONObjDataLength(x) ((x)->length - sizeof(short))
#define BSONObjGetPropertyId(x) (x)->propertyId

#define BSONObjData(x) (x)->data

/**
 * 获取指定field的属性值
 */

extern Obj* getField(BSONObj *bson, short propertyId);
extern void addElement(BSONObj *bson, BSONObj *ele);
extern void addProperty(BSONObj *bson, short propertyId, Obj *value);


#endif
